/* eslint-disable no-undef */
import { Request } from '@/request/index.js'
import uvUI from '@climblee/uv-ui'
import * as Pinia from 'pinia'
import piniaPluginPersistedstate from 'pinia-plugin-persistedstate'
import { createSSRApp } from 'vue'
import App from './App.vue'

const toast = {
  success: async (title, duration = 1000, mask = true) => {
    await uni.showToast({
      title,
      icon: 'none',
      duration,
      mask,
    })
    await uni.$uv.sleep(duration)
  },
  loading: async (title, mask = true) => {
    await uni.showLoading({
      title,
      mask,
    })
  },
}
export function createApp() {
  const app = createSSRApp(App)
  const p = Pinia.createPinia()
  p.use(piniaPluginPersistedstate)
  app.use(p).use(uvUI)
  Request(Pinia)
  return {
    app,
    Pinia,
  }
}
